home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0213_Determine Easter Date.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  1.7 KB  |  62 lines

  1. {
  2. >
  3. > Has anyone an algorithm to determine moveable feasts - such as Easter -
  4. > which is calculated by the year? by any other method? 
  5.   
  6. Popular question this past 2 days. Here is our kcEaster function from our KingCalendar product. Just pass it the year and it will
  7. return a TDateTime for Easter. Enjoy the code, it was a fun to write<G> 
  8.   
  9. function kcEaster( nYear: Integer ): TDateTime;
  10. var
  11.    nMonth, nDay, nMoon, nEpact, nSunday, nGold, nCent, nCorx, nCorz: Integer;
  12.  begin
  13.  
  14.     { The Golden Number of the year in the 19 year Metonic Cycle }
  15.     nGold := ( ( nYear mod 19 ) + 1  );
  16.  
  17.     { Calculate the Century }
  18.     nCent := ( ( nYear div 100 ) + 1 );
  19.  
  20.     { No. of Years in which leap year was dropped in order to keep in step
  21.       with the sun }
  22.     nCorx := ( ( 3 * nCent ) div 4 - 12 );
  23.  
  24.     { Special Correction to Syncronize Easter with the moon's orbit }
  25.     nCorz := ( ( 8 * nCent + 5 ) div 25 - 5 );
  26.  
  27.     { Find Sunday }
  28.     nSunday := ( ( 5 * nYear ) div 4 - nCorx - 10 );
  29.  
  30.     { Set Epact (specifies occurance of full moon }
  31.     nEpact := ( ( 11 * nGold + 20 + nCorz - nCorx ) mod 30 );
  32.  
  33.     if ( nEpact < 0 ) then
  34.        nEpact := nEpact + 30;
  35.  
  36.     if ( ( nEpact = 25 ) and ( nGold > 11 ) ) or ( nEpact = 24 ) then
  37.        nEpact := nEpact + 1;
  38.  
  39.     { Find Full Moon }
  40.     nMoon := 44 - nEpact;
  41.  
  42.     if ( nMoon < 21 ) then
  43.        nMoon := nMoon + 30;
  44.  
  45.     { Advance to Sunday }
  46.     nMoon := ( nMoon + 7 - ( ( nSunday + nMoon ) mod 7 ) );
  47.  
  48.     if ( nMoon > 31 ) then
  49.        begin
  50.          nMonth := 4;
  51.          nDay   := ( nMoon - 31 );
  52.        end
  53.     else
  54.        begin
  55.          nMonth := 3;
  56.          nDay   := nMoon;
  57.        end;
  58.  
  59.     Result := EncodeDate( nYear, nMonth, nDay );
  60.  
  61.  end;
  62.